<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>vue-router之编程式导航</title>
    <script src="../../vue.js" type="text/javascript"></script>
    <script src="vue-router.js" type="text/javascript"></script>
</head>
<body>
<div id="app">
    <router-link to="/">index</router-link>
    <router-link to="/list">list</router-link>
    <router-link to="/list/one">listOne</router-link>
    <router-link to="/list/two">listTwo</router-link>
    <router-view></router-view>
    <button @click="change">跳转</button>
</div>
<script>
    var router=new VueRouter({
        routes:[
            {
                path:'/',
                component:{
                    template:`<div>首页</div>`
                }
            },
            {
                path:'/list',
                component:{
                    template:`<div>列表</div>`
                }
            },
            {
                path:'/list/:item',
                component:{
                    template:`<div>{{$route.params.item}}</div>`
                }
            }
        ]
    })

    var app=new Vue({
        el: "#app",
        router:router,
        methods:{
            change:function () {
                setTimeout(function () {
                    this.router.push('/list/two')
                    setTimeout(function () {
                        this.router.replace('/list/one')
                    },2000)
                },2000);
                this.$router.go(-1)
            }
        }
    })
</script>
</body>
</html>